Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide metadata for the calculation of extra_state_attributes #56

Merged
merged 2 commits into from
Jun 21, 2024

Conversation

dmulcahey
Copy link
Contributor

@dmulcahey dmulcahey commented Jun 21, 2024

Usage in HA. Done this way to account for the potential future where properties are removed and we only have dicts shared from the lib to HA.

    @property
    def extra_state_attributes(self) -> Mapping[str, Any] | None:
        """Return entity specific state attributes."""
        if self.entity_data.entity.extra_state_attribute_names is not None:
            state_data = self.entity_data.entity.state
            extra_state_attributes = {}
            for name in self.entity_data.entity.extra_state_attribute_names:
                if name in state_data and state_data[name] is not None:
                    extra_state_attributes[name] = state_data[name]
            return extra_state_attributes
        return None

Copy link

codecov bot commented Jun 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.89%. Comparing base (ad272d1) to head (34cad7a).

Additional details and impacted files
@@           Coverage Diff           @@
##              dev      #56   +/-   ##
=======================================
  Coverage   94.89%   94.89%           
=======================================
  Files          61       61           
  Lines        9064     9076   +12     
=======================================
+ Hits         8601     8613   +12     
  Misses        463      463           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dmulcahey dmulcahey merged commit d971bab into dev Jun 21, 2024
6 checks passed
@dmulcahey dmulcahey deleted the dm/fix-extra-state-attributes branch August 18, 2024 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant